package top.hzy520.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.HeaderHttpSessionStrategy;
import org.springframework.session.web.http.HttpSessionStrategy;
import top.hzy520.common.constants.Parameter;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 21:09 2018/5/30
 */
@Configuration
@EnableRedisHttpSession
public class HttpSessionConfig {
    @Autowired
    private Parameter parameter;
    @Bean
    public HttpSessionStrategy httpSessionStrategy(){
        return new HeaderHttpSessionStrategy();
    }
    @Bean
    public JedisConnectionFactory connectionFactory(){
        JedisConnectionFactory jedisConnectionFactory=new JedisConnectionFactory();
        String host=parameter.getRedisHost().split(":")[0];
        int port=Integer.valueOf(parameter.getRedisHost().split(":")[1]);
        jedisConnectionFactory.setHostName(host);
        jedisConnectionFactory.setPort(port);
        jedisConnectionFactory.setTimeout(2000);
        return jedisConnectionFactory;
    }
}
